﻿Imports System.Web.UI.Design
Imports System.ComponentModel.Design
Imports System.IO
Imports System.Web.UI

Namespace Controls
    Public Class TabControlDesigner
        Inherits ControlDesigner
        Protected Overloads Overrides Function GetEmptyDesignTimeHtml() As String
            Return CreatePlaceHolderDesignTimeHtml("右击选择创建新的属性页")
        End Function

        Private _verbs As DesignerVerbCollection

        Public Overloads Overrides ReadOnly Property Verbs() As DesignerVerbCollection
            Get
                If _verbs Is Nothing Then
                    _verbs = New DesignerVerbCollection(New DesignerVerb() {New DesignerVerb("创建新的属性页...", New EventHandler(AddressOf Me.OnBuildTabStrip))})
                End If

                Return _verbs
            End Get
        End Property


        Private Sub OnBuildTabStrip(ByVal sender As Object, ByVal e As EventArgs)
            Dim oEditor As New TabEditor()
            oEditor.EditComponent(Me.Component)
        End Sub

        Public Overloads Overrides Function GetDesignTimeHtml() As String

            Try
                Dim oTabStrip As TabControl = DirectCast(Component, TabControl)

                If oTabStrip.Items Is Nothing OrElse oTabStrip.Items.Count = 0 Then
                    Return GetEmptyDesignTimeHtml()
                End If

                Dim oSB As New System.Text.StringBuilder()
                Dim oStringWriter As New StringWriter(oSB)
                Dim oWriter As New HtmlTextWriter(oStringWriter)

                oTabStrip.RenderDownLevelContent(oWriter)
                oWriter.Flush()
                oStringWriter.Flush()

                Return oSB.ToString()
            Catch ex As Exception
                Return CreatePlaceHolderDesignTimeHtml("生成设计时代码错误:" & Chr(10) & "" & Chr(10) & "" + ex.ToString())
            End Try
        End Function

    End Class
End Namespace